package com.zmh.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.zmh.model.Role;

/** 
 * @author zhoumh
 * @version 创建时间：2017年5月30日 下午2:26:51 
 * @Description 
*/
@Repository
public class RoleDao {
	@Autowired
	private JdbcTemplate jdbcTemplate;
	String selectRole = "select id,uuid,name from sys_role";
	
	public int selectCount(){
		int rowCount = this.jdbcTemplate.queryForObject("select count(*) from sys_role", Integer.class);
		System.out.println(rowCount);
		return rowCount;
	}
	/**
	 * 
	 * @author zhoumh
	 * @version 创建时间：2017年5月30日 下午3:03:13
	 */
	public void selectRole(){
		List<Role> roles = new ArrayList<>();
		roles=jdbcTemplate.queryForList(selectRole,Role.class);
		System.out.println(roles.size());
		for (Role role : roles) {
			System.out.println(role.getName());
		}
	}
	public String selectTest(){
		return selectRole;
	}
	
	 public Role mapRow(ResultSet rs, int rowNum) throws SQLException {
		 Role role = new Role();
		 role.setId(rs.getInt("id"));
		 role.setName(rs.getString("name"));
		 role.setUuid(rs.getString("uuid"));
	      return role;
	   }
}
